package com.verssor.data.daos;

import com.verssor.model.EntityBase;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.lang.reflect.ParameterizedType;


public abstract class DaoBase<T extends EntityBase> {

    
    @PersistenceContext(unitName = "primary")
    protected EntityManager em;
    
    
    
    Class<T> getGenericParamater() {
        return (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
    }
    
   public T findById(Integer idEntity){
      return  em.find(getGenericParamater(),idEntity);        
    }

    public T create(T entity){
        em.persist(entity);
        return entity;
    }
    

    
    
    
}
